import 'package:flutter/material.dart';

class SliderWidget extends StatefulWidget {
  final double max;
  final double min;
  final double defaultVal;
  final int divisions;
  final Function(double) onChange;

  SliderWidget({@required this.max, @required this.min, @required this.defaultVal, @required this.divisions, @required this.onChange});

  @override
  _SliderState createState() {
    return _SliderState();
  }
}
class _SliderState extends State<SliderWidget> {
  double sliderVal;

  @override
  void initState() {
    super.initState();
    this.sliderVal = widget.defaultVal;
  }

  void setValue(double val) {
    setState(() {
      this.sliderVal = val;
      widget.onChange(val);
    });
  }
  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        Expanded(
          child: Slider(
            value: this.sliderVal,
            max: widget.max,
            min: widget.min,
            label: (this.sliderVal.toInt()).toString(),
            divisions: widget.divisions,
            onChanged: this.setValue,
          ),
        ),
        Text(sliderVal.toInt().toString())
      ],
    );
  }
}